#!/usr/bin/env python
import zmq

class ZmqServer(object):
	ctx = None
	def __init__(self, sock_type, port):
		assert isinstance(port,str),"'port' must be a string."

		if Server.ctx==None:
			print("Create a zmq.Context.")
			Server.ctx = zmq.Context()

		self.ctx_ = Server.ctx
		self.sock_ = self.ctx_.socket(sock_type)
		addr = "tcp://*:{0}".format(port)
		print("Server bind to {0}.".format(addr))
		self.sock_.bind(addr)

	def send(self,msg):
		self.sock_.send(msg)

	def recv(self):
		return self.sock_.recv()


class ZmqServerPub(ZmqServer):
	def __init__(self,port):
		super(ZmqServerPub,self).__init__(sock_type=zmq.PUB,port=port)

	def recv(self):
		pass


class ZmqServerRep(ZmqServer):
	def __init__(self,port):
		super(ZmqServerRep,self).__init__(sock_type=zmq.REP,port=port)

